﻿using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using Maticsoft.DBUtility;//Please add references
namespace hcrainMvc.DAL
{
	/// <summary>
	/// 数据访问类:ym_web_ld
	/// </summary>
	public partial class ym_web_ld
	{
		public ym_web_ld()
		{}
		#region  BasicMethod



		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(hcrainMvc.Model.ym_web_ld model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into ym_web_ld(");
			strSql.Append("ldid,smid,url,项目名称,楼名,建设工程规划许可证,建筑工程施工许可证)");
			strSql.Append(" values (");
			strSql.Append("@ldid,@smid,@url,@项目名称,@楼名,@建设工程规划许可证,@建筑工程施工许可证)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@ldid", MySqlDbType.Double),
					new MySqlParameter("@smid", MySqlDbType.VarChar,50),
					new MySqlParameter("@url", MySqlDbType.VarChar,250),
					new MySqlParameter("@项目名称", MySqlDbType.VarChar,50),
					new MySqlParameter("@楼名", MySqlDbType.VarChar,50),
					new MySqlParameter("@建设工程规划许可证", MySqlDbType.VarChar,50),
					new MySqlParameter("@建筑工程施工许可证", MySqlDbType.VarChar,50)};
			parameters[0].Value = model.ldid;
			parameters[1].Value = model.smid;
			parameters[2].Value = model.url;
			parameters[3].Value = model.项目名称;
			parameters[4].Value = model.楼名;
			parameters[5].Value = model.建设工程规划许可证;
			parameters[6].Value = model.建筑工程施工许可证;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(hcrainMvc.Model.ym_web_ld model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update ym_web_ld set ");
			strSql.Append("ldid=@ldid,");
			strSql.Append("smid=@smid,");
			strSql.Append("url=@url,");
			strSql.Append("项目名称=@项目名称,");
			strSql.Append("楼名=@楼名,");
			strSql.Append("建设工程规划许可证=@建设工程规划许可证,");
			strSql.Append("建筑工程施工许可证=@建筑工程施工许可证");
			strSql.Append(" where ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@ldid", MySqlDbType.Double),
					new MySqlParameter("@smid", MySqlDbType.VarChar,50),
					new MySqlParameter("@url", MySqlDbType.VarChar,250),
					new MySqlParameter("@项目名称", MySqlDbType.VarChar,50),
					new MySqlParameter("@楼名", MySqlDbType.VarChar,50),
					new MySqlParameter("@建设工程规划许可证", MySqlDbType.VarChar,50),
					new MySqlParameter("@建筑工程施工许可证", MySqlDbType.VarChar,50)};
			parameters[0].Value = model.ldid;
			parameters[1].Value = model.smid;
			parameters[2].Value = model.url;
			parameters[3].Value = model.项目名称;
			parameters[4].Value = model.楼名;
			parameters[5].Value = model.建设工程规划许可证;
			parameters[6].Value = model.建筑工程施工许可证;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete()
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from ym_web_ld ");
			strSql.Append(" where ");
			MySqlParameter[] parameters = {
			};

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public hcrainMvc.Model.ym_web_ld GetModel()
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ldid,smid,url,项目名称,楼名,建设工程规划许可证,建筑工程施工许可证 from ym_web_ld ");
			strSql.Append(" where ");
			MySqlParameter[] parameters = {
			};

			hcrainMvc.Model.ym_web_ld model=new hcrainMvc.Model.ym_web_ld();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public hcrainMvc.Model.ym_web_ld DataRowToModel(DataRow row)
		{
			hcrainMvc.Model.ym_web_ld model=new hcrainMvc.Model.ym_web_ld();
			if (row != null)
			{
					//model.ldid=row["ldid"].ToString();
				if(row["smid"]!=null)
				{
					model.smid=row["smid"].ToString();
				}
				if(row["url"]!=null)
				{
					model.url=row["url"].ToString();
				}
				if(row["项目名称"]!=null)
				{
					model.项目名称=row["项目名称"].ToString();
				}
				if(row["楼名"]!=null)
				{
					model.楼名=row["楼名"].ToString();
				}
				if(row["建设工程规划许可证"]!=null)
				{
					model.建设工程规划许可证=row["建设工程规划许可证"].ToString();
				}
				if(row["建筑工程施工许可证"]!=null)
				{
					model.建筑工程施工许可证=row["建筑工程施工许可证"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ldid,smid,url,项目名称,楼名,建设工程规划许可证,建筑工程施工许可证 ");
			strSql.Append(" FROM ym_web_ld ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM ym_web_ld ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.id desc");
			}
			strSql.Append(")AS Row, T.*  from ym_web_ld T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "ym_web_ld";
			parameters[1].Value = "id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

